<!--
 * Created by PhpStorm.
 * User: jackhhy
 * Date: 2019/7/12-10:10
 * Link: https://gitee.com/luckygyl/lucky_admin
 * FileName: listalbum.html
 *-->


{include file="public/head" /}

<body>
<!-- 正文开始 -->
<div class="layui-fluid">

    <div class="layui-row layui-col-space10">

        <div class="layui-col-md12">

            <div class="layui-card">
                <div class="layui-card-body layui-row ">
                    <form action="" class="layui-form" method="get" >
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">相册名称：</label>
                                <div class="layui-input-inline">
                                    <input name="name" class="layui-input" value="" type="text" placeholder="相册名称">
                                </div>
                            </div>

                            <div class="layui-inline" style="padding-left: 20px;">
                                <button class="layui-btn icon-btn" lay-filter="search" lay-submit="">
                                    <i class="layui-icon"></i>搜索
                                </button>
                                <button class="layui-btn icon-btn layui-btn-normal"  onclick="javascript:window.location.reload();" >
                                    <i class="layui-icon layui-icon-refresh"></i> 重置
                                </button>

                                <a class="layui-btn icon-btn layui-btn-warm " href="{:url('album/index')}" onmouseover="tis(this)" data-title="切换到图集模式" >
                                    <i class="layui-icon layui-icon-list"></i> 图集模式
                                </a>
                            </div>

                        </div>

                    </form >
                </div>

            </div>

            <!--右侧表格开始-->
            <div class="layui-card">
                <div class="layui-card-header" style="line-height: 72px;">
                    <div class="layui-btn-container do_btn">
                       <button class="layui-btn layui-btn-sm layui-btn-danger"  data-type="del"><i class="layui-icon layui-icon-delete"></i>删除</button>
                        <button class="layui-btn layui-btn-sm" data-type="add_menu"> <i class="layui-icon">&#xe61f;</i>新增相册</button>
                        <button class="layui-btn layui-btn-sm layui-btn-primary"  data-type="reload"> <i class="fa fa-refresh"></i> 刷新</button>
                    </div>
                </div>
                <div class="layui-card-body">

                    <div class="yys-fluid yys-wrapper">
                        <div class="layui-row lay-col-space20">
                            <div class="layui-cos-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
                                <section class="yys-body">
                                    <div class="yys-body-content clearfix changepwd">
                                        <div class="layui-col-lg12 layui-col-md10 layui-col-sm12 layui-col-xs12" style="width:100%">
                                            <div class="user-tables">
                                                <table id="tableFilter" lay-filter="tableFilter"> </table>
                                            </div>
                                        </div>
                                    </div>
                                </section>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
            <!--右侧表格结束-->

        </div>


    </div>




</div>


<style type="text/css">
    .layui-table-cell{
        text-align:center;
        height: auto;
        white-space: normal;
    }
    .layui-table img{
        max-width:300px;
        max-height: 50px;
    }
</style>


<!--模板-->
<script type="text/html" id="operationTpl">
    <a href="javascript:;"   class="layui-btn layui-btn-xs "  onmouseover="tis(this)"  data-title="查看相册" lay-event="view"><i class="layui-icon layui-icon-camera"></i></a>
    <a href="javascript:;"   class="layui-btn layui-btn-normal layui-btn-xs "  onmouseover="tis(this)"  data-title="编辑相册" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
    <a href="javascript:;"   class="layui-btn layui-btn-warm layui-btn-xs "  onmouseover="tis(this)"  data-title="添加相册图片" lay-event="add"><i class="layui-icon layui-icon-add-circle" ></i></a>

</script>


<script type="text/html" id="is_open">
    <input type="checkbox" name="is_open"  lay-data="{{d.is_open}}" value="{{d.id}}"  lay-filter="is_open" lay-skin="switch"   lay-text="加密|不加密"  {{ d.is_open == 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="is_show">
    <input type="checkbox" name="is_show"  lay-data="{{d.is_show}}" value="{{d.id}}"  lay-filter="is_show" lay-skin="switch"  lay-text="是|否"  {{ d.is_show == 1 ? 'checked' : '' }}>
</script>

<script type="text/html" id="is_top">
    <input type="checkbox" name="is_top"  lay-data="{{d.is_top}}" value="{{d.id}}"  lay-filter="is_top" lay-skin="switch"  lay-text="是|否"  {{ d.is_top == 1 ? 'checked' : '' }}>
</script>

{include file="public/js" /}


<script>

    layui.use(['element', 'table', 'form', 'jquery', 'laydate','util','tree'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var laydate = layui.laydate;
        var tree=layui.tree;
        var util=layui.util;

        form.render();

        // layer.load(2);
        table.render({
            elem: '#tableFilter',
            url:"{:url('album/listalbum')}",
            toolbar: true,
            even: true, //开启隔行背景
            id:'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','last'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                ,groups: 5 //只显示 1 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
                ,limit:30
                ,limits:[30,40,50,60,70,80,90,100]
            },
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {type: 'checkbox'},
                {field: 'img', title: '相册封面', style:'cursor: pointer;',width: 150, align: "center",templet:function (d) {
                        return '<img src="'+d.img+'"  layer-index="0" alt="无图" style="height:100px;" />';
                    }},
                {field: 'name', minWidth: 130, title: '相册名称'},
                {field: 'nums', width: 80, title: '数量',sort:true},
                {field: 'describe', minWidth: 150, title: '相册描述'},
                {field:'is_open',title:'是否加密',templet: '#is_open',width:110 ,unresize: true},
                {field: 'password',style:'cursor: pointer;',title: '加密密码',width:130},
                {field:'is_show',title:'是否显示',templet: '#is_show',width:100 ,unresize: true},
                {field: 'tags',style:'cursor: pointer;',title: '标签',width:150},
                {field:'is_top',title:'是否置顶',templet: '#is_top',width:100 ,unresize: true},
                {field: 'hits',style:'cursor: pointer;',title: '点击量',width:90,sort:true},
                {field: 'time_formt', title: '添加时间',align: 'center',width:200},
                {fixed: 'right',templet: '#operationTpl', width: 190, align: 'center', title: '操作'}
            ]],
            done: function (res) {
                layer.closeAll('loading');
                hoverOpenImg();
            }
        });


        /**
         * 鼠标悬浮显示大图
         *
         */
        function hoverOpenImg(){
            var img_show = null; // tips提示
            $('td img').hover(function(){
                var img = "<img class='img_msg' src='"+$(this).attr('src')+"' style='width:100%;' />";
                img_show = layer.tips(img, this,{
                    tips:[2, 'rgba(41,41,41,.0)']
                    ,area: ['12%']
                });
            },function(){
                layer.close(img_show);
            });
        }


        /**
         * 表格搜索
         */
        form.on('submit(search)', function (obj) {
            CreateSearch("table_id",obj.field); //查询
            return false;
        });



        /**
         * 监听是否显示操作
         */
        form.on('switch(is_show)', function(obj){
            var _id=parseInt(obj.value);
            var pan=obj.elem.checked;
            var status;
            if (pan===false){
                status=2;
            }else {
                status=1;
            }
            change_status("table_id","album",_id,"is_show",status);
        });


        form.on('switch(is_top)', function(obj){
            var _id=parseInt(obj.value);
            var pan=obj.elem.checked;
            var status;
            if (pan===false){
                status=0;
            }else {
                status=1;
            }
            change_status("table_id","album",_id,"is_top",status);
        });


        /**
         * 监听单行工具操作
         */
        table.on('tool(tableFilter)', function (obj) {
            var data = obj.data;

            var _id=parseInt(data.id);
            var layEvent = obj.event;
            if (layEvent==="view"){
                var open=parseInt(data.is_open);
                if (open==1){
                    layer.prompt({
                        btn: ['确定'],
                        title: '请输入相册密码！',
                        closeBtn: 1,
                        formType: 1,
                        shade: 0.5,
                    }, function (value, index) {
                        $.post("{:url('album/pass_lock')}",{password:value,id:_id},function (res) {
                            if (res.code==1){
                                layer.close(index);
                                layer.msg(res.msg,{icon: 1, time: 1500,shade:0.3, anim: 4},function () {
                                    var url="/index.php/admin/album/ViewImages/id/"+_id;
                                    var p_layui = parent.layui;//获取父级的layui
                                    var p_okTab = p_layui.okTab();//拿到导航操作对象
                                    var page = '<a lay-id="u-"+_id href="javascript:;" data-url="' + url + '"><cite>查看相册</cite><span class="layui-badge-dot"></span></a>';
                                    p_okTab.tabAdd(page);
                                });
                            }else {
                                layer.msg(res.msg, {anim: 6,time:1500});
                                return false;
                            }
                        });
                    });
                } else {
                    var url="/index.php/admin/album/ViewImages/id/"+_id;
                    var p_layui = parent.layui;//获取父级的layui
                    var p_okTab = p_layui.okTab();//拿到导航操作对象
                    var page = '<a lay-id="u-"+_id href="javascript:;" data-url="' + url + '"><cite>查看相册</cite><span class="layui-badge-dot"></span></a>';
                    p_okTab.tabAdd(page);
                }

            }else if(layEvent==="edit"){

                var url="/index.php/admin/album/EditAlbum/id/"+_id;
                CreateForm("编辑相册",'50%','75%',url);
                return false;

            }else if(layEvent==="add"){

                var url="/index.php/admin/album/AddImages/id/"+_id;
                CreateForm("上传相册图片",'50%','65%',url);
                return false;
            }

        });


        var active = {
            add_menu:function(){
                var url="{:url('album/AddAlbum')}";
                CreateForm("添加相册",'50%','75%',url);
                return false;
            },
            del: function(){ //获取选中数据
                var checkStatus = table.checkStatus('table_id'),data = checkStatus.data;
                var num=0;
                var id=[];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                delete_data(id,"{:url('album/delete')}","table_id","确定删除选中的相册吗？删除后相册图片会放到回收相册中！");
            },
            reload: function(){
                CreateReload("table_id");
            },
            move:function () {
                var checkStatus = table.checkStatus('table_id'),data = checkStatus.data;
                var num=0;
                var id=[];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                layer.msg("功能待开发",{time:1500});return false;
            }

        };

        $('.do_btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });



    });

</script >


</body >
</html >